<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>展示</title>
    <%--需要引入各种css、js、jquery的插件--%>
    <script type="text/javascript" src="easyui1.7/jquery.min.js"></script>
    <script type="text/javascript" src="easyui1.7/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui1.7/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="easyui1.7/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="easyui1.7/themes/icon.css"/>
</head>
<body>
<div id="dg">
    <c:if test="${user.role_name=='普通管理员'}">
        <input type="hidden" id="day1" value="5">
    </c:if>
    <c:if test="${user.role_name=='超级管理员'}">
        <input type="hidden" id="day2" value="5">
    </c:if>
    欢迎你${user.username} {${user.role_name}}<br>
    <c:if test="${user.role_name!='普通员工'}">
        请假人: <input type="text" id="username">
        时间1: <input type="date" id="time1">
        时间2: <input type="date" id="time2">
        <button onclick="searchQleave()">搜索</button>
        <br>
        <button onclick="agree()">批量同意</button>
        <button onclick="refuse()">批量拒绝</button>
    </c:if>
    <c:if test="${user.role_name=='普通员工'}">
        <input type="hidden" id="user_id" value="${user.id}">
        <button>
            <a href="qleave.jsp">我要请假</a>
        </button>
        <button onclick="goDelete()">批量删除</button>
    </c:if>
</div>
<table id="tg"></table>
</body>
<script>
    $(function () {
        show()
    })
    function searchQleave() {
        show()
    }
    function show() {
        $('#tg').datagrid({
            url:'searchQleave',
            fitColumns:true,
            columns:[[
                {field:'xz',title:'',checkbox:true},
                {field:'id',title:'流程编号'},
                {field:'username',title:'请假人'},
                {field:'create_time',title:'请假时间'},
                {field:'type',title:'请假类型'},
                {field:'days',title:'请假天数'},
                {field:'reason',title:'请假原因'},
                {field:'status',title:'审批状态'},
                {field:'cz',title:'操作',formatter:function (value,row,index) {
                        if (row.status=='待审批' && ${user.role_name!='普通员工'}){
                            var str1 = "<button>"+"<a href=agreeById?id="+row.id+">同意</a>"+"</button>"
                            var str2 = "<button>"+"<a href=refuseById?id="+row.id+">拒绝</a>"+"</button>"
                            return str1+"  "+str2
                        }else if (${user.role_name=='普通员工'}){
                            var str1 = "<button>"+"<a href=deleteById?id="+row.id+">删除</a>"+"</button>"
                            return str1
                        }
                    }},
            ]],
            pagination:true,
            pageNumber:1,
            pageSize:2,
            pageList:[2,3,4],
            toolbar:'#dg',
            queryParams:{
                username:$('#username').val(),
                time1:$('#time1').val(),
                time2:$('#time2').val(),
                day1:$('#day1').val(),
                day2:$('#day2').val(),
                user_id:$('#user_id').val()
            }
        })
    }
    function agree() {
        var arr = $('#tg').datagrid("getSelections")
        if (arr.length!=0){
            var s="";
            for (var i in arr){
                s+=arr[i].id+","
            }
            location.href="${pageContext.request.contextPath}/agree?ids="+s
        }
    }
    function refuse() {
        var arr = $('#tg').datagrid("getSelections")
        if (arr.length!=0){
            var s="";
            for (var i in arr){
                s+=arr[i].id+","
            }
            location.href="${pageContext.request.contextPath}/refuse?ids="+s
        }
    }
    function goDelete() {
        var arr = $('#tg').datagrid("getSelections")
        if (arr.length!=0){
            var s="";
            for (var i in arr){
                s+=arr[i].id+","
            }
            location.href="${pageContext.request.contextPath}/goDelete?ids="+s
        }
    }
</script>
</html>
